package com.xdjd.mobile.business.dao.daoservice.activity;

import com.xdjd.mobile.business.dao.mapper.activity.ActivityUserClockPoDao;
import com.xdjd.mobile.business.entity.model.activity.ActivityUserClockPo;
import net.oschina.durcframework.easymybatis.PageInfo;
import net.oschina.durcframework.easymybatis.query.Query;
import net.oschina.durcframework.easymybatis.query.Sort;
import net.oschina.durcframework.easymybatis.util.QueryUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2019/1/10 0010.
 */
@Service
public class ActivityUserClockPoService {

    @Autowired
    private ActivityUserClockPoDao activityUserClockPoDao;

    public List<ActivityUserClockPo> checkClockingRecord(Long memberId) {
        Query query = new Query().eq("member_id", memberId).eq("status", 1);
        return activityUserClockPoDao.findAll(query);
    }

    public void saveUserClock(ActivityUserClockPo po) {
        po.setCreateTime(new Date());
        po.setModifyTime(new Date());
        activityUserClockPoDao.save(po);
    }

    public ActivityUserClockPo findByMemberId(Long memberId) {
        Query query = new Query().eq("member_id", memberId).eq("status", 1);
        return activityUserClockPoDao.getByExpression(query);
    }

    public ActivityUserClockPo findByClockNo(String clockNo) {
        Query query = new Query().eq("clock_no", clockNo);
        return activityUserClockPoDao.getByExpression(query);
    }

    public int addBonusPool(String clockNo, Long bonus) {
        return activityUserClockPoDao.addBonusPool(clockNo, bonus);
    }

    public int reduceRemainDay(String clockNo) {
        return activityUserClockPoDao.reduceRemainDay(clockNo);
    }

    public PageInfo<ActivityUserClockPo> getAllValid(Long memberId, Integer pageIndex, Integer pageSize) {
        Query query = new Query().eq("member_id", memberId).in("status", Arrays.asList(1, 2));
        query.addSort("create_time", Sort.DESC);
        query.page(pageIndex, pageSize);
        return QueryUtils.query(activityUserClockPoDao, query);
    }
}
